home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / GWMALLOC.ZIP;1 / GWMALLOC.TAR / gw_malloc / chunk_loc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-08  |  5.2 KB  |  159 lines

  1. /*
  2.  * local defines for the low level memory routines
  3.  *
  4.  * Copyright 1992 by Gray Watson and the Antaire Corporation
  5.  *
  6.  * This file is part of the malloc-debug package.
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library (see COPYING-LIB); if not, write to the
  20.  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  *
  22.  * The author of the program may be contacted at gray.watson@antaire.com
  23.  *
  24.  * $Id: chunk_loc.h,v 1.9 1993/04/05 22:29:58 gray Exp $
  25.  */
  26.  
  27. #ifndef __CHUNK_LOC_H__
  28. #define __CHUNK_LOC_H__
  29.  
  30. /* defines for the malloc subsystem */
  31. #define BASIC_BLOCK        12    /* basic block size in bits */
  32. #define SMALLEST_BLOCK         4    /* smallest block size in bits */
  33. #define LARGEST_BLOCK        24    /* allowable allocation in bits */
  34. #define LARGEST_NORMAL_BLOCK    16    /* largest normal allocation in bits */
  35.  
  36. #define BLOCK_SIZE        (1 << BASIC_BLOCK)
  37.  
  38. #define IS_DBLOCK(size)        ((size) < BLOCK_SIZE)
  39.  
  40. /* number of blocks in the administrative structures */
  41. #define BB_PER_ADMIN    ((BLOCK_SIZE - \
  42.               (sizeof(long) + sizeof(int) + sizeof(char *) + \
  43.                sizeof(long))) / sizeof(bblock_t))
  44. #define DB_PER_ADMIN    ((BLOCK_SIZE - (sizeof(long) + sizeof(long))) \
  45.              / sizeof(dblock_t))
  46.  
  47. #define CHUNK_MAGIC_BASE    0xDEA007    /* base magic number */
  48. #define CHUNK_MAGIC_TOP        0x976DEAD    /* top magic number */
  49.  
  50. #define WHAT_BLOCK(pnt)        (((long)(pnt) / BLOCK_SIZE) * BLOCK_SIZE)
  51. #define CHUNK_TO_USER(pnt)    ((pnt) + pnt_below_adm)
  52.  
  53. /* bb_flags values */
  54. #define BBLOCK_ALLOCATED    0x3F        /* block has been allocated */
  55. #define BBLOCK_START_USER    0x01        /* start of some user space */
  56. #define BBLOCK_USER        0x02        /* allocated by user space */
  57. #define BBLOCK_ADMIN        0x04        /* pointing to bblock admin */
  58. #define BBLOCK_DBLOCK        0x08        /* pointing to divided block */
  59. #define BBLOCK_DBLOCK_ADMIN    0x10        /* pointing to dblock admin */
  60. #define BBLOCK_FREE        0x20        /* block is free */
  61.  
  62. /*
  63.  * single divided-block administrative structure
  64.  */
  65. struct dblock_st {
  66.   union {
  67.     struct {
  68.       unsigned short    nu_size;        /* size of contiguous area */
  69.       unsigned short    nu_line;        /* line where it was alloced */
  70.     } in_nums;
  71.     
  72.     struct bblock_st    *in_bblock;        /* pointer to the bblock */
  73.   } db_info;
  74.   
  75.   /* to reference union and struct elements as db elements */
  76. #define db_bblock    db_info.in_bblock    /* F */
  77. #define db_size        db_info.in_nums.nu_size    /* U */
  78. #define db_line        db_info.in_nums.nu_line    /* U */
  79.   
  80.   union {
  81.     struct dblock_st    *pn_next;        /* next in the free list */
  82.     char        *pn_file;        /* .c filename where alloced */
  83.   } db_pnt;
  84.   
  85.   /* to reference union elements as db elements */
  86. #define db_next        db_pnt.pn_next        /* F */
  87. #define db_file        db_pnt.pn_file        /* U */
  88.   
  89. };
  90. typedef struct dblock_st    dblock_t;
  91.  
  92. /*
  93.  * single basic-block administrative structure
  94.  */
  95. struct bblock_st {
  96.   unsigned short    bb_flags;        /* what it is */
  97.   
  98.   union {
  99.     unsigned short    nu_bitc;        /* chunk size */
  100.     unsigned short    nu_line;        /* line where it was alloced */
  101.   } bb_num;
  102.   
  103.   /* to reference union elements as bb elements */
  104. #define bb_bitc        bb_num.nu_bitc        /* DF */
  105. #define bb_line        bb_num.nu_line        /* U */
  106.   
  107.   union {
  108.     unsigned int    in_count;        /* admin count number */
  109.     dblock_t        *in_dblock;        /* pointer to dblock info */
  110.     struct bblock_st    *in_next;        /* next in free list */
  111.     unsigned int    in_size;        /* size of allocation */
  112.   } bb_info;
  113.   
  114.   /* to reference union elements as bb elements */
  115. #define bb_count    bb_info.in_count    /* A */
  116. #define    bb_dblock    bb_info.in_dblock    /* D */
  117. #define    bb_next        bb_info.in_next        /* F */
  118. #define    bb_size        bb_info.in_size        /* U */
  119.   
  120.   union {
  121.     struct dblock_adm_st    *pn_slotp;    /* pointer to db_admin block */
  122.     struct bblock_adm_st    *pn_adminp;    /* pointer to bb_admin block */
  123.     char            *pn_mem;    /* memory associated to it */
  124.     char            *pn_file;    /* .c filename where alloced */
  125.   } bb_pnt;
  126.   
  127.   /* to reference union elements as bb elements */
  128. #define    bb_slotp    bb_pnt.pn_slotp        /* a */
  129. #define    bb_adminp    bb_pnt.pn_adminp    /* A */
  130. #define    bb_mem        bb_pnt.pn_mem        /* DF */
  131. #define    bb_file        bb_pnt.pn_file        /* U */
  132.   
  133. };
  134. typedef struct bblock_st    bblock_t;
  135.  
  136. /*
  137.  * collection of bblock admin structures
  138.  */
  139. struct bblock_adm_st {
  140.   long            ba_magic1;        /* bottom magic number */
  141.   int            ba_count;        /* position in bblock array */
  142.   bblock_t        ba_block[BB_PER_ADMIN];    /* bblock admin info */
  143.   struct bblock_adm_st    *ba_next;        /* next bblock adm struct */
  144.   long            ba_magic2;        /* top magic number */
  145. };
  146. typedef struct bblock_adm_st    bblock_adm_t;
  147.  
  148. /*
  149.  * collection of dblock admin structures
  150.  */
  151. struct dblock_adm_st {
  152.   long            da_magic1;        /* bottom magic number */
  153.   dblock_t        da_block[DB_PER_ADMIN];    /* dblock admin info */
  154.   long            da_magic2;        /* top magic number */
  155. };
  156. typedef struct dblock_adm_st    dblock_adm_t;
  157.  
  158. #endif /* ! __CHUNK_LOC_H__ */
  159.